//
//  WXAlert.m
//  触碰点
//
//  Created by 王勇 on 16/9/9.
//  Copyright © 2016年 王勇. All rights reserved.
//

#import "WXAlert.h"
#import "AppDelegate.h"

@implementation WXAlert

+(void)showAlert:(NSString *)text buttonArray:(NSArray *)buttonNames buttonAction:(void (^)(int))buttonAction{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Info" message:text preferredStyle:UIAlertControllerStyleAlert];
    
    if ([buttonNames isKindOfClass:[NSArray class]] && buttonNames.count>0) {
        int index = 0;
        for (NSString *btnName in buttonNames) {
            [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                if (buttonAction) {
                    buttonAction(index);
                }
            }]];
            index++;
        }
    }else {
        [alertController addAction:[UIAlertAction actionWithTitle:@"default titlle" style:UIAlertActionStyleDefault handler:nil]];
    }
    
    UIViewController *rootVC = [[UIApplication sharedApplication].delegate window].rootViewController;
    
    [rootVC presentViewController:alertController animated:true completion:nil];
}

+(void)showAlert:(NSString *)text buttonAction:(void (^)(void))buttonAction{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Info" message:text preferredStyle:UIAlertControllerStyleAlert];
    
    [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (buttonAction) {
            buttonAction();
        }
    }]];
    
    UIViewController *rootVC = [[UIApplication sharedApplication].delegate window].rootViewController;
    
    
    [rootVC presentViewController:alertController animated:true completion:nil];
}




@end
